package xyz.xtt.schedule.message;

import com.google.common.collect.Lists;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class AssetEventMessage {
	private static final String MINT_EVENT = "mint";
	private static final String TRANSFER_FROM = "transferFrom";
	private static final String BURN = "burn";
	private Long ts;
	private String eventName;
	private Long from;
	private Long to;
	private Long assetId;
	private String dealHash;
	private Long transactionOrderId;
	private String bizId;
	private String assetType;

	public static AssetEventMessage buildMinEvent(Long assetId, Long to, String transactionHash, Long orderId, String bizId, String assetType) {
		return AssetEventMessage
				.builder()
				.ts(System.currentTimeMillis())
				.eventName(MINT_EVENT)
				.from(0L)
				.to(to)
				.assetId(assetId)
				.dealHash(transactionHash)
				.transactionOrderId(orderId)
				.bizId(bizId)
				.assetType(assetType)
				.build();
	}

	public static AssetEventMessage buildTransferFromEvent(Long assetId, Long from, Long to, String transactionHash, Long orderId, String bizId,
			String assetType) {
		return AssetEventMessage
				.builder()
				.ts(System.currentTimeMillis())
				.eventName(TRANSFER_FROM)
				.from(from)
				.to(to)
				.assetId(assetId)
				.dealHash(transactionHash)
				.transactionOrderId(orderId)
				.bizId(bizId)
				.assetType(assetType)
				.build();
	}

	public static AssetEventMessage buildBurnEvent(Long assetId, Long from, String transactionHash, Long orderId, String bizId, String assetType) {
		return AssetEventMessage
				.builder()
				.ts(System.currentTimeMillis())
				.eventName(BURN)
				.from(from)
				.to(0L)
				.assetId(assetId)
				.dealHash(transactionHash)
				.transactionOrderId(orderId)
				.bizId(bizId)
				.assetType(assetType)
				.build();
	}

	public static void main(String[] args) {
		AssetEventMessage buildBurnEvent = AssetEventMessage
				.buildBurnEvent(1874027091391397888L, 7279779987431673856L, "0x373eee857ef5ccda9a989d8559e17fe51504bc1360dcc1ba80a91385d1bb9ac6", 1874036554059968512L, "115500400008", "LAND");
		System.out.println(JSONUtil.toJsonStr(Lists.newArrayList(buildBurnEvent)));
	}
}
